//切换销量及销售额
	$(".control-mode").click(function() {
		if (!$(this).hasClass("active")) {
			$(".control-mode").removeClass("active");
			$(this).addClass("active");
			if($(this).text()=="商品销量排行"){
				$(".saleType").text("销量");
				$(".GoodsBusiness").text("商品名称");
				$(".BusinessName").css("display","table-cell");
				var formObject={"pageSize":10,"type":$(".control-mode.active").attr("data-value")};
				loadTableData(formObject);
			}else if($(this).text()=="商品销售额排行"){
				$(".saleType").text("销售额(元)");
				$(".GoodsBusiness").text("商品名称");
				$(".BusinessName").css("display","table-cell");
				var formObject={"pageSize":10,"type":$(".control-mode.active").attr("data-value")};
				loadTableData(formObject);
			}else if($(this).text()=="商家销售额排行"){
				$(".saleType").text("销售额(元)");
				$(".GoodsBusiness").text("商家名称");
				$(".BusinessName").css("display","none");
				var formObject={};
				loadTableBusinessData(formObject);
			}

		}
	});


	
	//加载列表信息
	var formObject={"pageSize":10,"type":"sales"}
	var TableData={};
	loadTableData(formObject);
	function loadTableData(GetData){
		zxTips_loading({
			loadicon:true,//是否添加加载图标（默认添加）
			loadtxt:"加载中"//加载说明
		});

		$.ajax({
			type:"POST",
			url:DataURL+"sys/goods/sales",
			dataType:'json', 
			async : false,
			contentType :"application/json;charset=UTF-8",
			data: JSON.stringify(GetData),//传递给服务器的参数
			success:function(data){
				if(checkTokenError(data)){
				//console.log(data);
				EntryTable(data.content);
				}
			},
	        error:function(data){
	            console.log(data);
	            zxTips_short({
	    			txt : "系统错误"
	    			});
	        }
		});
		zxTips_loadingend();
	}
	function loadTableBusinessData(GetData){
		zxTips_loading({
			loadicon:true,//是否添加加载图标（默认添加）
			loadtxt:"加载中"//加载说明
		});

		$.ajax({
			type:"POST",
			url:DataURL+"sys/goods/business/sales",
			dataType:'json', 
			async : false,
			contentType :"application/json;charset=UTF-8",
			data: JSON.stringify(GetData),//传递给服务器的参数
			success:function(data){
				if(checkTokenError(data)){
				//console.log(data);
				EntryBusinessTable(data.content);
				}
			},
	        error:function(data){
	            console.log(data)
	            zxTips_short({
	    			txt : "系统错误"
	    			});
	        }
		});
		zxTips_loadingend();
	}
	
//输入数据
	function EntryTable(TableData) {
		console.log(TableData);
		TableData.sort(DataSortByQuantity);
		var TableList = "";
		if(TableData.length!=0){
		var maxQuantity=TableData[0].quantity;
		for (var i = 0; i <TableData.length; i++) {
			var ranking=i+1;
			var WidthPercent=TableData[i].quantity/TableData[0].quantity*100;
			TableList += '<tr>';
			TableList += '<td>'+ranking+'</td>';
			TableList += '<td><a href="'+HostURL+'/sys/goods/toGoodsDetail?id='+TableData[i].goodsId+'&backStatics=1"><span class="list-name" data-id="'+TableData[i].goodsId+'">'+TableData[i].goodsName+'</span></a></td>';
			TableList += '<td>'+TableData[i].categoryName+'</td>';
			TableList += '<td>'+'<div class="statisticsNumber floatLeft">'+TableData[i].quantity+'</div>'+'<div class="progress">'
			TableList += '<div class="progress-bar" role="progressbar" aria-valuemin="0" aria-valuemax="100" style="width: '+WidthPercent+'%;">';
			TableList += '</div>';
			TableList += '</div></td>';
			TableList += '<td><span>'+TableData[i].businessName+'</span></td>';
			TableList += '</tr>';
		}
		
	}
		else{TableList +='<tr><td colspan="5">没有查询到数据</td><tr>'}
		$('#MyTable').find('tbody').html(TableList);
		}
	
	function EntryBusinessTable(TableData) {
		console.log(TableData);
		TableData.sort(DataSortByQuantity);
		var TableList = "";
		if(TableData.length!=0){
		var maxQuantity=TableData[0].quantity;
		for (var i = 0; i <TableData.length; i++) {
			var ranking=i+1;
			var WidthPercent=TableData[i].quantity/TableData[0].quantity*100;
			TableList += '<tr>';
			TableList += '<td>'+ranking+'</td>';
			TableList += '<td><a href="'+HostURL+'/sys/business/toBusinessDetail?id='+TableData[i].businessId+'&backStatics=1"><span class="list-name" data-id="'+TableData[i].businessId+'">'+TableData[i].businessName+'</span></a></td>';
			TableList += '<td>'+TableData[i].categoryName+'</td>';
			TableList += '<td>'+'<div class="statisticsNumber floatLeft">'+TableData[i].quantity+'</div>'+'<div class="progress">'
			TableList += '<div class="progress-bar" role="progressbar" aria-valuemin="0" aria-valuemax="100" style="width: '+WidthPercent+'%;">';
			TableList += '</div>';
			TableList += '</div></td>';
			TableList += '</tr>';
		}
		
	}
		else{TableList +='<tr><td colspan="5">没有查询到数据</td><tr>'}
		$('#MyTable').find('tbody').html(TableList);
		}
	//根据销量排序
	function DataSortByQuantity(x, y) {
        return (x.quantity < y.quantity) ? 1 : -1
        		 
    }

	//选择时间区间
	$(".TimeInterval .mode").click(function() {
		if (!$(this).hasClass("active")) {
			$(".TimeInterval .mode").removeClass("active");
			$(this).addClass("active");
		}
	});
	//搜索页面
	$(".table-sreaching-bar .btn-search").click(function() {
		if($(".control-mode.active").attr("data-value")=="")
		{
			var formObject={
				 "pageSize":10,
				 "businessName":$(".table-sreaching-bar .value1").val(),
				 "categoryId":$(".table-sreaching-bar .value2").val(),
				 "countRange":$(".TimeInterval .mode.active").attr("data-value"),
				};
			loadTableBusinessData(formObject);
		}
		else{
		var formObject={
				"pageSize":10,
				"type":$(".control-mode.active").attr("data-value"),
				 "businessName":$(".table-sreaching-bar .value1").val(),
				 "categoryId":$(".table-sreaching-bar .value2").val(),
				 "countRange":$(".TimeInterval .mode.active").attr("data-value"),
				};
		
		loadTableData(formObject);
		}
		 });
	
	

	

	

	
